package solution._0100._0101;

import com.sun.jmx.remote.internal.ArrayQueue;
import common.TreeNode;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;

/**
 * Created by chen_snow
 * Date: 2021/6/23 21:59
 * Description: 对称二叉树
 */
public class Solution {
    public boolean isSymmetric(TreeNode root) {
        Queue<TreeNode> data = new LinkedList<TreeNode>();
        data.add(root);
        data.add(root);

        while (!data.isEmpty()) {
            TreeNode first = data.poll();
            TreeNode second = data.poll();

            if (first == null && second == null) {
                continue;
            }

            if ((first == null || second == null) || first.val != second.val) {
                return false;
            }

            data.add(first.left);
            data.add(second.right);
            data.add(first.right);
            data.add(second.left);
        }
        return true;
    }


}
